#include "../source/http/http_server.h"
#include "../source/log.h"
#include <memory>

void test()
{
    MYHTTP::HttpServer::ptr server = std::make_shared<MYHTTP::HttpServer>();
    Address::ptr addr = Address::LookupAny("0.0.0.0:8020");
    while(!server->bind(addr))
    {
        sleep(2);
    }

    auto sd = server->getServletDispatch();
    sd->addServlet("/lightning/haha", [](MYHTTP::HttpRequest::ptr request
                                                ,MYHTTP::HttpResponse::ptr response
                                                ,MYHTTP::HttpSession::ptr session){
        response->setBody(request->toString());
        return 0;
    });

    sd->addGlobServlet("/lightning/*", [](MYHTTP::HttpRequest::ptr request
                                                ,MYHTTP::HttpResponse::ptr response
                                                ,MYHTTP::HttpSession::ptr session){
        response->setBody("Glob:\n\r" + request->toString());
        return 0;
    });
    server->start();
}

int main(void)
{
    IOManager iom(2);
    iom.schedule(test);

    return 0;
}